package itbour.onetouchshow.widget.circlemenu;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.annotation.AttrRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.FrameLayout;
import android.widget.ImageView;

import itbour.onetouchshow.R;


/**
 * Created by dingmouren on 2017/6/12.
 */

public class ShadowImageView extends FrameLayout {
    private ImageView mImageView;//图片
    private int mImgId;

    public ShadowImageView(@NonNull Context context) {
        this(context, null);
    }

    public ShadowImageView(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ShadowImageView(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        // setBackgroundColor(UIUtils.getColor(android.R.color.transparent));
        //获取自定义属性值
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ShadowImageView);
        if (attrs == null) return;
        try {
            mImgId = a.getResourceId(R.styleable.ShadowImageView_src, -1);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            a.recycle();
        }
        mImageView = new ImageView(context);
        mImageView.setScaleType(ImageView.ScaleType.FIT_XY);
        mImageView.setImageResource(mImgId);
        addView(mImageView);
        // int xPadding = (int) (mShadowRadius + Math.abs(mShadowOffsetX));
        //  int yPadding = (int) (mShadowRadius + Math.abs(mShadowOffsetY));
        //  setPadding(xPadding, yPadding, xPadding, yPadding);
    }

    public ImageView getmImageView() {
        return mImageView;
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        if (w > 0 && h > 0) {
            //setBackgroundCompat(w, h);
        }
    }

//    @Override
//    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
//        measureChild(getChildAt(0), widthMeasureSpec, heightMeasureSpec);
//    }

}
